// 为不同类型的错误创建具体的错误类，可以携带更丰富的上下文信息，方便调试和处理。

export class NetworkError extends Error {
  constructor(message?: string) {
    super(message ?? "A network error occurred");
    this.name = "NetworkError";
  }
}

export class BadRequestError extends Error {
  constructor(public details: object | string = {}) {
    super("Bad Request");
    this.name = "BadRequestError";
    // 可以在此处根据details类型做进一步处理，比如格式化输出
  }
}

export class UnauthorizedError extends Error {
  constructor(message: string = "Unauthorized") {
    super(message);
    this.name = "UnauthorizedError";
  }
}
export class ForbiddenError extends Error {
  constructor(
    message: string = "You don't have permission to access this resource"
  ) {
    super(message);
    this.name = "ForbiddenError";
    this.statusCode = 403; // HTTP状态码，表示禁止访问
  }

  readonly statusCode: number; // 添加只读属性来存储HTTP状态码
}
export class NotFoundError extends Error {
  constructor(public resource?: string) {
    super(
      `Not Found: ${
        resource ? `Resource ${resource} not found` : "General not found error"
      }`
    );
    this.name = "NotFoundError";
  }
}

export class ServerError extends Error {
  constructor(public message: string = "An error occurred on the server") {
    super(message);
    this.name = "ServerError";
  }
}


export class DefaultError extends Error {
    constructor(message: string) {
      super(message);
      this.name = 'DefaultError';
    }
    
  }
  
